
# load packages
library(tidyverse)

# read data
meta_df_raw <- read_csv("data/issue-meta-raw.csv") %>%
  glimpse()

# clean data
meta_df <- meta_df_raw %>%
  separate(codebook_label, into = LETTERS[1:3], sep = "\\.") %>%
  select(-A, -B) %>%
  rename(complete_question = C) %>%
  mutate(complete_question = str_trim(complete_question)) %>%
  mutate(stem = str_replace(complete_question, "Do you favor or oppose ", "...")) %>%
  mutate(issue_id = paste("Issue", issue_id)) %>%
  mutate(category = str_to_title(category),
         issue = str_to_title(issue)) %>%
  glimpse() %>%
  write_csv("output/issue-meta.csv")
